package com.eascs.admin.o2o.loan.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;

import com.alibaba.dubbo.config.annotation.Service;
import com.eascs.admin.o2o.internal.util.StatusContexts;
import com.eascs.admin.o2o.loan.dao.LoanapplyOpLogDao;
import com.eascs.admin.o2o.loan.entity.O2oLoanBksyInfo;
import com.eascs.app.dao.PageResult;
import com.eascs.app.dao.SqlPageQuery;
import com.eascs.common.util.StringUtil;
@Service
public class O2oLoanBksyService implements IO2oLoanGsScService<O2oLoanBksyInfo> {

	@Autowired
	LoanapplyOpLogDao dao;
	
	public int insertEntity(O2oLoanBksyInfo t) {
		return dao.insert(t);
	}

	public int updateEntity(O2oLoanBksyInfo t) {
		return dao.updateById(t);
	}

	public O2oLoanBksyInfo getEntityById(String id) {
		return dao.getById(O2oLoanBksyInfo.class, id);
	}

	public List<O2oLoanBksyInfo> queryEntitys(O2oLoanBksyInfo t) {
		return null;
	}
	
	public int queryEntitysSize(String loanapplyNo ) {
		String sql =  "select count(*) from o2o_loan_bksy_info where loanapply_id=? and is_delete = 'N' ";
		return dao.findInteger(sql, loanapplyNo);
	}

	public PageResult<Object[]> queryPage(O2oLoanBksyInfo t, int pageSize, int pageIndex) {
		SqlPageQuery<Object[]> pageQuery = new SqlPageQuery<>(Object[].class, pageSize, pageIndex);
		String querySql = "select id,supplier,purchase,cooperation,period,loanapply_id from o2o_loan_bksy_info where 1=1 ";
		if(StringUtil.isNotBlank(t.getLoanapplyId())){
			querySql = querySql + " and loanapply_id=? ";
			pageQuery.addParam(t.getLoanapplyId());
		}
		querySql = querySql + " and is_delete=? "; 
		pageQuery.addParam(StatusContexts.O2O_NO);
		pageQuery.setQuerySql(querySql);
		return dao.findDataWithPage(pageQuery);
	}

}
